package com.mall.server.controller;

import com.mall.commons.R;
import com.mall.commons.exceotion.BusinessException;
import com.mall.commons.exceotion.ErrorResult;
import com.mall.server.service.ReturnApplyService;
import com.tanhua.model.dto.OmsOrderReturnApplyDto;
import com.tanhua.model.dto.OmsOrderReturnApplyUpdateDto;
import com.tanhua.model.dto.ReturnApplyDto;
import com.tanhua.model.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/returnApply")
public class ReturnApplyController {

    @Autowired
    private ReturnApplyService returnApplyService;

    /**
     * 分页查询退货申请
     *
     * @param returnApplyDto
     * @return
     */
    @GetMapping("/list")
    public R listOmsOrderReturnApply(ReturnApplyDto returnApplyDto) {
        PageVo pageVo = returnApplyService.listOmsOrderReturnApply(returnApplyDto);
        if (pageVo == null) {
            throw new BusinessException(ErrorResult.emptyError());
        }
        return R.success(pageVo);
    }

    /**
     * 获取退货申请详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        OmsOrderReturnApplyDto ooo0 = returnApplyService.getById(id);
        return R.success(ooo0);
    }

    /**
     * 修改退货申请状态
     *
     * @param id
     * @param dto
     * @return
     */
    @PostMapping("/update/status/{id}")
    public R updates(@PathVariable Integer id, @RequestBody OmsOrderReturnApplyUpdateDto dto) {
        returnApplyService.updates(id, dto);
        return R.success("操作成功");
    }

    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R deletes(Integer[] ids) {
        returnApplyService.deletes(ids);
        return R.success("操作成功");
    }
}
